BackgroundInitializer
object BackgroundInitializer
Handles one-time iOS BGTaskScheduler setup.
MUST be called from your AppDelegate BEFORE the app finishes launching:
// AppDelegate.swift
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
BackgroundInitializerKt.initialize()
return true
}Content copied to clipboard
Also register all task identifiers in Info.plist:
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>sync-users</string>
<string>upload-logs</string>
</array>Content copied to clipboard
Internally registers handlers for every task ID in TaskRegistry. Each handler:
Emits TaskState.Running()
Executes the registered suspend function
Emits TaskState.Success or TaskState.Failed
Sets task completion via BGTask.setTaskCompletedWithSuccess
Attaches an expiration handler to gracefully handle OS interruption